package com.windfone.web.action;

import java.util.List;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.windfone.common.StringUtil;
import com.windfone.model.Askreponse;
import com.windfone.model.Fitting;
import com.windfone.model.Fittingtypebase;
import com.windfone.service.AskReponseService;
import com.windfone.service.FittingService;

public class PjCenterAction extends ActionSupport {
  
	/**	serialVersionUID */
	private static final long serialVersionUID = 1L;
	private FittingService fittingService;
	private int fittingId;
	private int basetypeId;
	private String selectTypeName;
	private String fittingTypeId;
	private List<Fitting> fittingList;
	private List<Fittingtypebase> fFittingtypebase;
	private List<Askreponse>  askReponses;
	
	public String getSelectTypeName() {
		return selectTypeName;
	}

	public void setSelectTypeName(String selectTypeName) {
		this.selectTypeName = selectTypeName;
	}
	public List<Askreponse> getAskReponses() {
		return askReponses;
	}

	public void setAskReponses(List<Askreponse> askReponses) {
		this.askReponses = askReponses;
	}
	private AskReponseService askReponseService;
	public FittingService getFittingService() {
		return fittingService;
	}

	public AskReponseService getAskReponseService() {
		return askReponseService;
	}

	public void setAskReponseService(AskReponseService askReponseService) {
		this.askReponseService = askReponseService;
	}

	public List<Fittingtypebase> getfFittingtypebase() {
		return fFittingtypebase;
	}

	public void setfFittingtypebase(List<Fittingtypebase> fFittingtypebase) {
		this.fFittingtypebase = fFittingtypebase;
	}

	public int getFittingId() {
		return fittingId;
	}

	public int getBasetypeId() {
		return basetypeId;
	}

	public String getFittingTypeId() {
		return fittingTypeId;
	}

	public List<Fitting> getFittingList() {
		return fittingList;
	}

	public void setFittingService(FittingService fittingService) {
		this.fittingService = fittingService;
	}

	public void setFittingId(int fittingId) {
		this.fittingId = fittingId;
	}

	public void setBasetypeId(int basetypeId) {
		this.basetypeId = basetypeId;
	}

	public void setFittingTypeId(String fittingTypeId) {
		this.fittingTypeId = fittingTypeId;
	}

	public void setFittingList(List<Fitting> fittingList) {
		this.fittingList = fittingList;
	}

	public String execute() throws Exception {
		fFittingtypebase = fittingService.getAllFittingtypebase();
//		fittingList = fittingService.getFittingByTypeId(fittingTypeId);
		return SUCCESS;
	}
	private String peijianId;
	private Fitting fitting;
	public Fitting getFitting() {
		return fitting;
	}

	public void setFitting(Fitting fitting) {
		this.fitting = fitting;
	}

	public String getPeijianId() {
		return peijianId;
	}

	public void setPeijianId(String peijianId) {
		this.peijianId = peijianId;
	}

	public String pjFenlei() throws Exception {
//		fFittingtypebase = fittingService.getAllFittingtypebase();
		if ( fittingTypeId != null &&  !"".equals( fittingTypeId )){
			if ( StringUtil.isInteger(  fittingTypeId )){
				fittingList = fittingService.getFittingByTypeId(Integer.parseInt(  fittingTypeId ));
				if ( fittingList.size()>0){
					selectTypeName =fittingService.getFittingTypeById( fittingList.get(0).getFittingTypeId()).get(0).getName();  
				}
				
			}
		}
		return SUCCESS;
	}
	
	public String pjDetail() throws Exception {
//		fFittingtypebase = fittingService.getAllFittingtypebase();
		if ( peijianId != null &&  !"".equals( peijianId )){
			if ( StringUtil.isInteger(  peijianId )){
//		fittingList = fittingService.getFittingByTypeId(fittingTypeId);
				List<Fitting> fs =fittingService.getFittingById( Integer.parseInt(  peijianId ) );
				if ( fs.size()>0){
					fitting = fs.get(0);
					ServletContext application = ServletActionContext.getServletContext();  
			        WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);
			        if ( askReponseService == null ) 
			        	askReponseService  = (AskReponseService )wac.getBean("askReponseService");
					askReponses = askReponseService.getAskReponseByProductAndType(Integer.parseInt(  peijianId ), 2);
				}
			}
		}
		return SUCCESS;
	}
 
}
